package fr.jade.console.core;

import java.util.Map;


public class Help extends AbstractCommand implements Command {

  public String getDescription(){
    return "lists all commands";
  }
  
  public String getHelp(){
    return "help <cmd>";
  }
  public String getName() {
    return "help";
  }
  /**
   * @param pargs
   *          args[0] = cmdName
   */

  public Object execute(String[] args, Environment env) throws Throwable {
    JTerm shell = (JTerm)env.getEnvVar("shell");
    Map<String, Command> ctx = shell.getConsoleCommands();
    if(args.length == 1){
      for(Command c : ctx.values()){
        System.out.println(c.getName()+"\t"+c.getDescription());
      }
    }else{
      Command c = ctx.get(args[1]);
      if(c != null){
        System.out.println(c.getHelp());
      }else{
        System.err.println("JTerm: "+args[1]+" command not found");
      }
    }
    return null;
  }
  
}
